﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DBTramite.BussinesEntities;
using DBTramite.BussinesLogic;
using Microsoft.Practices.Unity;

namespace DBTramite.WebMVC4.Controllers
{
    public class TramiteController : Controller
    {
        [Dependency]
        public IT_SalidaService T_SalidaService { get; set; }

        [Dependency]
        public I_TDocumentoService DocumentoService { get; set; }

        //
        // GET: /Tramite/

        public ActionResult Index(Int32? page)
        {
            var lista = DocumentoService.GeDocumentosByOpcionAndCriterioPaged(0, "", page);

            return View(lista);
        }

        [HttpPost]
        public ActionResult Index(Int32 opcion,string criterio)
        {
            var lista = DocumentoService.GeDocumentosByOpcionAndCriterio(opcion, criterio);

            return View(lista);
        }

        public ActionResult Tramite()
        {
            var lista = T_SalidaService.GetSalidaByCriterio("");
            return View(lista);
        }

        [HttpPost]
        public ActionResult Tramite(string criterio = "")
        {
            var lista = T_SalidaService.GetSalidaByCriterio("");
            return View(lista);
        }

        //
        // GET: /Tramite/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Tramite/Create

        public ActionResult Tramitar(string id)
        {
            var documento = DocumentoService.GetT_DocumentoByNroExpediente(id);

            var salida = new T_Salida()
            {
                nroexpediente = documento.nroexpediente,
                nrodocumento = documento.nrodocumento,
                asunto = documento.asunto,
                fechasalida = DateTime.Now
            };


            return View(salida);
        }

        [HttpPost]
        public ActionResult Tramitar(T_Salida salida)
        {
            salida.fechasalida = DateTime.Now;
            T_SalidaService.AddSalida(salida);
            return RedirectToAction("Index");
        }

        //
        // POST: /Tramite/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Tramite/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Tramite/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Tramite/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Tramite/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
